package cn.edu.nju.freshdelivery.model;

import java.sql.Timestamp;
import java.util.HashSet;
import java.util.Set;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Transient;

import static javax.persistence.GenerationType.IDENTITY;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;

/**
 * Order entity. @author MyEclipse Persistence Tools
 */
@Entity
@Table(name = "order", catalog = "freshdelivery")
public class Order implements java.io.Serializable {

	// Fields

	private Integer id;
	private Seller seller;
	private Buyer buyer;
	private Timestamp startDate;
	private Integer state;
	private Double cost;
	private String name;
	private String address;
	private Integer phone;
	private Set<Orderdetail> orderdetails = new HashSet<Orderdetail>(0);

	// Constructors

	/** default constructor */
	public Order() {
	}

	/** minimal constructor */
	public Order(Seller seller, Buyer buyer, Timestamp startDate,
			Integer state, Double cost, String name, String address,
			Integer phone) {
		this.seller = seller;
		this.buyer = buyer;
		this.startDate = startDate;
		this.state = state;
		this.cost = cost;
		this.name = name;
		this.address = address;
		this.phone = phone;
	}

	/** full constructor */
	public Order(Seller seller, Buyer buyer, Timestamp startDate,
			Integer state, Double cost, String name, String address,
			Integer phone, Set<Orderdetail> orderdetails) {
		this.seller = seller;
		this.buyer = buyer;
		this.startDate = startDate;
		this.state = state;
		this.cost = cost;
		this.name = name;
		this.address = address;
		this.phone = phone;
		this.orderdetails = orderdetails;
	}

	// Property accessors
	@Id
	@GeneratedValue(strategy = IDENTITY)
	@Column(name = "id", unique = true, nullable = false)
	public Integer getId() {
		return this.id;
	}

	public void setId(Integer id) {
		this.id = id;
	}

	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "sid", nullable = false)
	public Seller getSeller() {
		return this.seller;
	}

	public void setSeller(Seller seller) {
		this.seller = seller;
	}

	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "bid", nullable = false)
	public Buyer getBuyer() {
		return this.buyer;
	}

	public void setBuyer(Buyer buyer) {
		this.buyer = buyer;
	}

	@Column(name = "startDate", nullable = false, length = 19)
	public Timestamp getStartDate() {
		return this.startDate;
	}

	public void setStartDate(Timestamp startDate) {
		this.startDate = startDate;
	}

	@Column(name = "state", nullable = false)
	public Integer getState() {
		return this.state;
	}

	public void setState(Integer state) {
		this.state = state;
	}

	@Column(name = "cost", nullable = false, precision = 22, scale = 0)
	public Double getCost() {
		return this.cost;
	}

	public void setCost(Double cost) {
		this.cost = cost;
	}

	@Column(name = "name", nullable = false, length = 45)
	public String getName() {
		return this.name;
	}

	public void setName(String name) {
		this.name = name;
	}

	@Column(name = "address", nullable = false, length = 65535)
	public String getAddress() {
		return this.address;
	}

	public void setAddress(String address) {
		this.address = address;
	}

	@Column(name = "phone", nullable = false)
	public Integer getPhone() {
		return this.phone;
	}

	public void setPhone(Integer phone) {
		this.phone = phone;
	}

	@Transient
//	@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY, mappedBy = "order")
	public Set<Orderdetail> getOrderdetails() {
		return this.orderdetails;
	}

	public void setOrderdetails(Set<Orderdetail> orderdetails) {
		this.orderdetails = orderdetails;
	}

}